package Action.user;

import Action.Sys.Setting;
import Bean.Log.UserLogEntity;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import org.hibernate.Session;
import tools.HibernateTools;

import java.util.List;

public class UserLogManage extends ActionSupport {
    int usid= (int)ActionContext.getContext().getSession().get("userid");//从session中获取
    List<UserLogEntity> data;
    String key;
    public String showlog(){
        Session session = HibernateTools.getSession();
        data=session.createQuery("from UserLogEntity where userId=?").setParameter(0, usid).getResultList();
        HibernateTools.commit(session);
        return SUCCESS;
    }
    public String userLoginLog(){
        Session session=HibernateTools.getSession();
        if (key==null||key.equals("")){
            data=session.createQuery("from UserLogEntity where cast(id as string ) like ? or cast(userId as string ) like ?  and flag=?")
                    .setParameter(0,"%"+key+"%")
                    .setParameter(1,"%"+key+"%")
                    .setParameter(2, Setting.UserLog_flag_UserLogin).getResultList();
        }
        return SUCCESS;
    }


    public List<UserLogEntity> getData() {
        return data;
    }
}
